// 导入组件
import { BrowserRouter as Router, Route, Switch, Redirect } from 'react-router-dom'

import Login from '@/pages/Login'
// import Layout from '@/pages/Layout'
import Layout from '@/pages/Layout'
import PrivateRoute from '@/components/PrivateRoute'
import MyCom from './components/test'

export default function App() {
  return (
    <Router>
      <div className='App'>
        <Switch>
          {/* 重定向的Route */}
          <Route
            exact
            path='/'
            render={() => {
              // 这里写类似于vue-router中导航守卫的功能
              console.log('跳转啦!!!!')
              return <Redirect to='/home' />
            }}
          />
          {/* 写死的规则 /-/home */}
          {/* <Redirect from='/' to='/home' /> */}
          <Route path='/login' component={Login}></Route>
          <PrivateRoute path='/home'>
            <Layout />
          </PrivateRoute>
          {/* <Route
            exact
            path='/'
            render={() => {
              // 判断是否已经登录
              if (isAuth()) {
                // 已登录 去首页
                return <Layout />
              } else {
                // 请先登录
                message.warning('请先登录')
                // 未登录 去登录页
                return <Redirect to='/login'></Redirect>
                // 重定向
                // 这里类似于vue-router中导航守卫的功能
                return <Redirect to='/home' />
              }
            } ></Route> */}
          <Route path='/login' component={Login}></Route>
          <Route path='/home' component={Layout} ></Route>
        </Switch>
      </div>
      <MyCom name='jack' age='18' friends={['西兰花', 'rose']}></MyCom>
    </Router>
  )
}
